/**
 * Created by Jing on 2018-02-26.
 */
import {
  call, put, all, takeLatest, select,
} from 'redux-saga/effects'
import { delay } from 'redux-saga'
import { listTable as listTableDuck } from 'ducks'

function* delayAction(action) {
  yield call(delay, 2000)
  yield put(listTableDuck.creators.actionReciveSearch(action.value))
}

function* reFetch(action) {
  if (action.func !== undefined) {
    yield call(action.func)
  }
}

export default function* sagas() {
  yield all([
    takeLatest(listTableDuck.types.CHANGE_SEARCH, delayAction),
    takeLatest(listTableDuck.types.CLOSE_MODAL, reFetch),
  ])
}
